package com.anycl.design.j2ee.servicelocator;

import lombok.extern.slf4j.Slf4j;

import java.util.LinkedList;
import java.util.List;

/**
 * 缓存类，用户缓存服务
 */
@Slf4j
public class Cache {
    // 用户存储缓存的容器
    private List<Service> services;

    public Cache() {
        this.services = new LinkedList<>();
    }

    public Service getService(String name) {
        for (Service service:services) {
            if (service.getName().equalsIgnoreCase(name)){
                log.info("从缓存容器中获取到了" + name);
                return service;
            }
        }
        return null;
    }

    public void addService(Service service) {
        services.add(service);
    }
}
